﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Interfleet.SE.UICompiler.Core.Batch
{
    /// <summary>
    /// This exception should be thrown when a batch file has
    /// an invalid xml structure.
    /// </summary>
    public class InvalidBatchXmlException : Exception
    {
        public InvalidBatchXmlException()
            : base()
        {

        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="expectedNode">name/xpath of the node missing</param>
        public InvalidBatchXmlException(string expectedNode)
            : base()
        {
            _expectedNode = expectedNode;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="expectedNode">name/xpath of the node missing<</param>
        /// <param name="expectedAttribute">name of the attribute missing</param>
        public InvalidBatchXmlException(string expectedNode, string expectedAttribute)
            : base()
        {
            _expectedNode = expectedNode;
            _expectedAttribute = expectedAttribute;
        }

        private string _message;
        private string _expectedNode;
        private string _expectedAttribute;

        public override string Message
        {
            get
            {
                string result = string.Empty;
                if (!string.IsNullOrEmpty(_expectedNode) && !string.IsNullOrEmpty(_expectedAttribute))
                {
                    return string.Format("Batch xml does not contain attribute '{0}' on node '{1}' as expected", _expectedAttribute);
                }
                else
                {
                    return string.Format("Batch xml does not contain node '{0}' as expected", _expectedNode);
                }
            }
        }
    }
}
